package com.copa.l232;

import java.util.Stack;

/**
 * @author copa
 * @createDate 2022-09-05 17:42
 * @function 普遍方法
 */
public class Test1 {

    private Stack<Integer> s1;
    private Stack<Integer> s2;

    public Test1() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        if (!s2.isEmpty()) {
            return s2.pop();
        }
        while (!s1.isEmpty()) {
            s2.push(s1.pop());
        }
        return s2.pop();
    }

    public int peek() {
        if (!s2.isEmpty()) {
            return s2.peek();
        }
        while (!s1.isEmpty()) {
            s2.push(s1.pop());
        }
        return s2.peek();
    }

    public boolean empty() {
        return s1.empty() && s2.empty();
    }

    /**
     * Your MyQueue object will be instantiated and called as such:
     * MyQueue obj = new MyQueue();
     * obj.push(x);
     * int param_2 = obj.pop();
     * int param_3 = obj.peek();
     * boolean param_4 = obj.empty();
     */
    public static void main(String[] args) {
//        Test1 obj = new Test1();
//        obj.push(1);
//        obj.push(2);
//        int param_2 = obj.pop();
//        System.out.println(param_2);
//        int param_3 = obj.peek();
//        System.out.println(param_3);
//        boolean param_4 = obj.empty();
//        System.out.println(param_4);
        Test1 obj = new Test1();
        obj.push(1);
        obj.push(2);
        obj.push(3);
        obj.push(4);
        System.out.println(obj.pop());
        obj.push(5);
        System.out.println(obj.pop());
        System.out.println(obj.pop());
        System.out.println(obj.pop());
        System.out.println(obj.pop());
    }
}
